<?php
/**
 * Date: 2018/2/6
 * Time: 16:44
 * Author: zeronlee
 */
namespace App\Models\Access\User\Traits;

trait UserRelate{


    /**
     * 绑定外部用户
     *
     * @param  object|array $relate
     * @return void
     */
    public function attachRelate($relate)
    {
        if (is_object($relate)) {
            $relateId = $relate->getKey();
        }

        if (is_array($relate)) {
            $relateId = $relate['id'];
        }

        $this->relation()->attach($relateId);
    }
    /**
     * 解绑外部用户
     *
     * @param  object|array $relate
     * @return void
     */
    public function detachRelate($relate)
    {
        if (is_object($relate)) {
            $relateId = $relate->getKey();
        }

        if (is_array($relate)) {
            $relateId = $relate['id'];
        }

        $this->relation()->detach($relateId);
    }

}